#!/usr/bin/env python

import os, sys, json


def main(argv):
    output_prefix = "output/"
    if not os.path.exists(output_prefix):
        os.system("mkdir "+output_prefix)

    output_task_usage = "output_task_usage/"
    output_job_events = "output_job_events/"
    users = os.listdir(output_job_events)
    task_usage = os.listdir(output_task_usage)

    for user in users:
        os.system("mkdir "+output_prefix+user)
        with open(output_job_events+user, "r") as f:
            job_events = json.load(f)
        for job in job_events:
            if os.path.exists(output_task_usage+job):
                mv_command = "mv "+output_task_usage+job+" "+output_prefix+user
                os.system(mv_command)


if __name__ == "__main__":
    main(sys.argv)